package com.cheer.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cheer.entity.MallAddressEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 收货地址表
 *
 * @author cheer
 */
@Mapper
@Repository
public interface MallAddressDao extends BaseMapper<MallAddressEntity> {

    default List<MallAddressEntity> selectListByUserId(Integer userId) {
        return selectList(new QueryWrapper<MallAddressEntity>()
                .eq("user_id", userId));
    }

    default void updateByUserId(Integer userId, MallAddressEntity address) {
        update(address, new QueryWrapper<MallAddressEntity>()
                .eq("user_id", userId));
    }

    default MallAddressEntity selectOneDefaultByUserId(Integer userId) {
        return selectOne(new QueryWrapper<MallAddressEntity>()
                .eq("user_id", userId)
                .eq("is_default", 1)
                .last("limit 1"));
    }
}
